package com.itheima.controller;

import com.itheima.anno.LogOperation;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    //班级列表查询
    @GetMapping
    public Result selectClazz(ClazzQueryParam clazzQueryParam) {

        PageResult<Clazz> pageResult = clazzService.selectClazz(clazzQueryParam);
        return Result.success(pageResult);
    }

    //删除班级
    @DeleteMapping("/{id}")
    @LogOperation
    public Result deleteClazz(@PathVariable("id") Integer id) {
        clazzService.deleteClazz(id);
        return Result.success();
    }

    //添加班级
    @PostMapping
    @LogOperation
    public Result insertClazz(@RequestBody Clazz clazz) {
        clazzService.insertClazz(clazz);
        return Result.success();
    }


    //根据id查询///修改部门前的数据回显
    @GetMapping("/{id}")
    public Result inquireById(@PathVariable Integer id) {
        Clazz clazz = clazzService.inquireById(id);
        return Result.success(clazz);
    }

    //修改部门
    @PutMapping
    @LogOperation
    public Result updateClazz(@RequestBody Clazz clazz) {
        clazzService.updateClazz(clazz);
        return Result.success();
    }

    //查询所有班级
    @GetMapping("/list")
    public Result selectAll() {
        List<Clazz> clazzList = clazzService.selectAll();
        return Result.success(clazzList);

    }

}
